﻿<?php 
function b() {print '<br/>';}

$search=$_GET["q"];
$count_printed_results=5;

$table=strtolower($_REQUEST["table"]);
//if (!$q) return;
require_once("konfiguration.html");
//if (strlen($q)<=2)$search=$q.'%';
//else $search='%'.$q.'%';
$result=mysql_query("SELECT distinct canword FROM $table WHERE canword like '{$search}%' ORDER BY canword LIMIT 5 ");
$result_count = mysql_num_rows($result);

//if ( ! $result ) { die('Error query: ' . mysql_error()); }

for($count = 0; $count <= $result_count; $count++) 
{
    $row=mysql_fetch_array($result);
	$result_array[$count]=$row[0];
    //if (strtolower($row[0])==$search)$result_array[0]=$row[0];
	//else $result_array[$count]=$row[0];
	
}
if (($result_count < $count_printed_results))
{
     $diff= $count_printed_results - $result_count;
	 $result2=mysql_query("SELECT distinct canword FROM $table WHERE canword like '%{$search}%' ORDER BY canword LIMIT {$diff} ");
	 for($count = 0; $count <= $result_count; $count++) 
	 {
		$row=mysql_fetch_array($result);
		$result_array[$count]=$row[0];
	 }
}

//if (in_array($q,$result_array2)) {print $q."\n";$result_array = array_diff($result_array, array($q));}
for($count = 0; $count <= $count_printed_results; $count++)if ($result_array[$count])print $result_array[$count]."\n"; 

?>
